package com.example.ssm1023.config;

import javafx.beans.binding.ObjectExpression;
import lombok.Data;

/**
 * 统一返回类型
 */
@Data
public class AppResult {

    private Integer code;
    private String msg;
    private Object data;

    public static AppResult success(ResultCode resultCode, Object data) {
        AppResult appResult = new AppResult();
        appResult.setCode(resultCode.getCode());
        appResult.setMsg(resultCode.getMsg());
        appResult.setData(data);
        return appResult;
    }
    public static AppResult success(Object data) {
        AppResult appResult = new AppResult();
        appResult.setCode(ResultCode.SUCCESS.getCode());
        appResult.setMsg(ResultCode.SUCCESS.getMsg());
        appResult.setData(data);
        return appResult;
    }

    public static AppResult success() {
        AppResult appResult = new AppResult();
        appResult.setCode(ResultCode.SUCCESS.getCode());
        appResult.setMsg(ResultCode.SUCCESS.getMsg());
        appResult.setData("");
        return appResult;
    }

    public static AppResult fail(ResultCode resultCode) {
        AppResult appResult = new AppResult();
        appResult.setCode(resultCode.getCode());
        appResult.setMsg(resultCode.getMsg());
        appResult.setData("");
        return appResult;
    }

    public static AppResult fail(ResultCode resultCode, Object data) {
        AppResult appResult = new AppResult();
        appResult.setCode(resultCode.getCode());
        appResult.setMsg(resultCode.getMsg());
        appResult.setData(data);
        return appResult;
    }



    public static AppResult fail(Object data) {
        AppResult appResult = new AppResult();
        appResult.setCode(ResultCode.FAIL.getCode());
        appResult.setMsg(ResultCode.FAIL.getMsg());
        appResult.setData(data);
        return appResult;
    }

}
